@page "/agents/projects/{serviceId}"
@using SDK.Authorization
@attribute [Authorize(Roles = $"{Roles.Administrator}, {Roles.Engineer}, {Roles.Reviewer}")]

@if (string.IsNullOrEmpty(_serviceName))
{
    <PageTitle>Projects</PageTitle>
}
else
{
    <PageTitle>Projects | @_serviceName</PageTitle>
}

<AyBorg.Web.Shared.Alerts.ServiceOfflineAlert IsVisible="@_hasServiceError" />
<div class="page-loading-bar">
    <MudProgressLinear Color="Color.Primary" Indeterminate="true" Class="my-0" hidden="@(!_isLoading)" />
</div>

<MudGrid class="pt-1">
    <MudItem xs="12">
        <MudCard Class="rounded-lg">
            <MudCardHeader>
                <CardHeaderAvatar>
                    <MudIcon Icon="@Icons.Material.Filled.GppBad" Size="Size.Large" Color="Color.Default" />
                </CardHeaderAvatar>
                <CardHeaderContent>
				    <MudText Typo="Typo.h6">Draft</MudText>
                </CardHeaderContent>
                <CardHeaderActions>
                    <MudButton Variant="Variant.Filled" StartIcon="@Icons.Material.Filled.AddBox" Color="Color.Primary" OnClick="@OnNewProjectClicked">New Project</MudButton>
                </CardHeaderActions>
			</MudCardHeader>
            <MudCardContent>
                <ProjectsTable
                    Projects="@_draftProjects"
                    OnProjectActivateClicked="@OnActivateProjectClicked"
                    OnProjectDeleteClicked="@OnProjectDeleteClicked"
                    OnProjectSaveAsReviewClicked="@OnSaveAsReviewClicked" />
            </MudCardContent>
        </MudCard>
    </MudItem>
    @if(_reviewProjects.Any())
    {
        <MudItem xs="12">
            <MudCard Class="rounded-lg">
                <MudCardHeader>
                    <CardHeaderAvatar>
                        <MudIcon Icon="@Icons.Material.Filled.SafetyCheck" Size="Size.Large" Color="Color.Warning" />
                    </CardHeaderAvatar>
                    <CardHeaderContent>
                        <MudText Typo="Typo.h6">Review</MudText>
                    </CardHeaderContent>
                </MudCardHeader>
                <MudCardContent>
                    <ProjectsTable
                        Projects="@_reviewProjects"
                        OnProjectActivateClicked="@OnActivateProjectClicked"
                        OnProjectDeleteClicked="@OnProjectDeleteClicked"
                        OnProjectSaveAsReadyClicked="@OnSaveAsReadyClicked"
                        OnProjectAbandonClicked="@OnAbandonReviewClicked" />
                </MudCardContent>
            </MudCard>
        </MudItem>
    }
    @if(_readyProjects.Any())
    {
        <MudItem xs="12">
            <MudCard Class="rounded-lg">
                <MudCardHeader>
                    <CardHeaderAvatar>
                        <MudIcon Icon="@Icons.Material.Filled.GppGood" Size="Size.Large" Color="Color.Success" />
                    </CardHeaderAvatar>
                    <CardHeaderContent>
                        <MudText Typo="Typo.h6">Ready</MudText>
                    </CardHeaderContent>
                </MudCardHeader>
                <MudCardContent>
                    <ProjectsTable
                        Projects="@_readyProjects"
                        OnProjectActivateClicked="@OnActivateProjectClicked"
                        OnProjectDeleteClicked="@OnProjectDeleteClicked" />
                </MudCardContent>
            </MudCard>
        </MudItem>
    }
</MudGrid>
